﻿using System;
using System.Windows;
using System.Windows.Controls;
using ParseControls;

namespace ParseOnlineAdmin
{
    /// <summary>
    /// Interaction logic for AddParseClass.xaml
    /// </summary>
    public partial class AddParseClass : UserControl
    {
        public AddParseClass()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // Context 
            ParseDataContext ctx = ((HostWindow)Application.Current.MainWindow)
                .DataContext as ParseDataContext;

            if (ctx == null)
                return;

            if (ctx.SelectedApp == null)
                return;

            // Check 
            if (this.txtName.Text != string.Empty)
            {
                // Item 
                ParseClass _app = new ParseClass();
                _app.GUID = Guid.NewGuid();
                _app.Name = this.txtName.Text;
                _app.ParseAppGUID = ((ParseApp)ctx.SelectedApp).GUID;

                // Package 
                ParseOne.Package.Classes.Add(_app);
                ParseOne.Package.Save();
                ParseOne.ReloadPackage();

                // Refresh 
                ParseOne.InformationSending(new ParseCustomEventArgs("Classes:Refresh"));
            }

            // Close Panel 
            ParseOne.InformationSending(new ParseCustomEventArgs("Panel:Close"));
        }
    }
}
